import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';

// 图片浏览
class PictureScan extends StatefulWidget {
  // 当前坐标
  final int initialIndex;

  // 图片列表
  final List<AssetEntity> items;

  // 是否显示bar
  final bool? isBarVisible;

  const PictureScan(
      {super.key,
      required this.initialIndex,
      required this.items,
      this.isBarVisible});

  @override
  State<PictureScan> createState() => _PictureScanState();
}

class _PictureScanState extends State<PictureScan> {

  Widget buildPic() {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        elevation: 0,
        foregroundColor: Colors.white,
      ),
      // extendBodyBehindAppBar: ,
      extendBodyBehindAppBar: true,
      backgroundColor: Colors.black,
      body: ExtendedImageGesturePageView.builder(
        controller: ExtendedPageController(
          initialPage: widget.initialIndex
        ),
        itemBuilder: (BuildContext context, int index) {
          final AssetEntity item = widget.items[index];
          return ExtendedImage(
            image: AssetEntityImageProvider(item, isOriginal: true),
            fit: BoxFit.contain,
            mode: ExtendedImageMode.gesture,
            initGestureConfigHandler: ((state) {
              return GestureConfig(
                  inPageView: true,
                  initialScale: 1.0,
                  minScale: 0.9,
                  animationMinScale: 0.7,
                  animationMaxScale: 3.5,
                  speed: 1,
                  maxScale: 3,
                  inertialSpeed: 100,
                  //you can cache gesture state even though page view page change.
                  //remember call clearGestureDetailsCache() method at the right time.(for example,this page dispose)
                  cacheGesture: false);
            }),
          );
        },
        itemCount: widget.items.length,
      ),
    );
  }
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        // Navigator.of(context).pop();
      },
      child: buildPic(),
    );
  }
}


